﻿/*  ----------------------------------------------------------------------------
 *  SysServer
 *  ----------------------------------------------------------------------------
 *  File:       DataEntityUserToken.cs
 *  Creater:     SEEN\MistSeen
 *  ----------------------------------------------------------------------------
 *  $Date: 2010-09-06 10:36:01 +0000 (Mon, 06 Sep 2010) $
 *  $Rev: 15 $
 *  $Author: ScorDeity $
 *  $URL: http://sysserver.googlecode.com/svn/trunk/src/SysServer/Sock/DataEntityUserToken.cs $
 *  $Id: DataEntityUserToken.cs 15 2010-09-06 10:36:01Z ScorDeity $
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

namespace SysServer.Sock
{
    /// <summary>
    /// 
    /// </summary>
    public class DataEntityUserToken : BaseUserToken
    {
        public Mediator  Mediator;
        public DataEntity DataEntity;

        internal int _StocketHandleNo;
        internal int BufferOffsetReceive;
        internal int BufferOffsetSend;

        private int _EntityId;
        public int EntityId
        {
            get { return this._EntityId; }
        }
        internal int  MessageEntityLenght;
        internal int  ReceivedMessageOffSet;

        internal Byte[] PrefixBuffer;
        internal int ReceivePrefixLength;
        internal int ReceivedPrefixBytesDoneCount = 0;
        internal int ReceivedMessageBytesDoneCount = 0;

        internal Byte[] _DataToSend;
        internal int _BytesSentAlreadyCount;
        internal int _SendBytesRemainingCount;
        internal int _SendPrefixLength;

        private Guid _SessionId;
        public Guid SessionId
        {
            get { return this.SessionId; }
        }

        public DataEntityUserToken(SocketAsyncEventArgs e,
            int receivceOffset, int sendOffset,
            int receivePrefixLenght, int sendPrefixLenght,
            int entityId)
        {
            this._EntityId = entityId;
            this.Mediator = new Mediator(e);
            this.BufferOffsetReceive = receivceOffset;
            this.BufferOffsetSend = sendOffset;
            this.ReceivePrefixLength = receivePrefixLenght;
            this._SendBytesRemainingCount = sendPrefixLenght;

            this.ReceivedMessageOffSet = receivceOffset + receivePrefixLenght;
        }

        internal void CreateNewDateEntiy()
        {
            this.DataEntity = new DataEntity();
        }
        internal void CreateSessionId()
        {
            this._SessionId = Guid.NewGuid();
        }

    }
}